<template>
	<custom-navigation-bar :title="data.shopName"></custom-navigation-bar> 
	<view style="margin-top: 160rpx;height:auto;float: left;width: 100%;">
		<view class="item">
			商户名：<label class="lb">{{data.shopName}}</label>
		</view>
		<view class="item">
			状态：
			<label class="lb" v-if="data.status==0">待审核</label>
			<label class="lb" v-if="data.status==1">正常</label>
			<label class="lb" v-if="data.status==2">未通过</label>
		</view>
		<view class="item">
			模块：<label class="lb">{{data.moduleName}}</label>
		</view>
		<view class="item">
			标签：<label class="lb">{{data.tags}}</label>
		</view> 
		<view class="item">
		 	联系人：<label class="lb">{{data.name}}</label>
		</view>
		<view class="item">
		 	联系电话：<label class="lb">{{data.phone}}</label>
		</view>
		<view class="item">
		  	性别：<label v-if="data.sex==0" class="lb">男</label><label v-if="data.sex==1" class="lb">女</label>
		</view> 
		<view class="item">
			地址：<label class="lb">{{data.position}}</label>
		</view>
		<view class="item">
			<map @click="openMap" style="width: 100%; height: 300rpx;float: left;" :latitude="data.latitude" :longitude="data.longitude" >
			</map>
		</view> 
		<view class="item">
			法人姓名：<label class="lb">{{data.legalPersonName}}</label>
		</view>
		<view class="item">
			法人身份证号：<label class="lb">{{data.legalPersonIdCard}}</label>
		</view>
		<view class="item">
			法人身份证照：<label class="clk" @click="previewImage(data.idImage[0])" >照片1</label>&nbsp;&nbsp;
			            <label class="clk" @click="previewImage(data.idImage[1])" >照片2</label>
		</view>
		<view class="item">
			营业执照：<label class="clk" @click="previewImage(data.licenseImage)" >查看</label>
		</view>
		<view class="item">
			其他资料：
			<label v-for="(item,index) in data.files" :key="index" class="clk" @click="previewImage(item)" >资料{{index+1}}</label>
		</view> 
		<view class="item" v-if="data.status==0">
			<view class="btn2" @click="un()">不通过</view>
		 	<view class="btn1" @click="edit(1,'')">通过</view> 
		</view>
		<view class="item" v-if="data.status==1"> 
			<view class="btn2" @click="un()">不通过</view>
		</view>
		<view class="item" v-if="data.status==2">
			<view class="btn2" @click="edit(1,'')">通过</view>
		</view>
	</view>
</template>

<script setup>
	import CustomNavigationBar from '@/components/CustomNavigationBar.vue'; 
	import { ref } from "vue"; 
	import http from '../../../utils/http';
	const id=ref(0);
	const userId=ref();
	const shopId=ref();
	import {
		onLoad,
		onPageScroll
	} from '@dcloudio/uni-app';
	onLoad((query) => {
		id.value=query.id;
		shopId.value=query.shopId;
		userId.value=getApp().globalData.user.userId; 
		initData();
	})
	function un(){ 
		uni.showModal({
		    title: '输入原因',
		    editable: true,
		    success: function (res) {
		        if (res.confirm) {
		            console.log('用户输入的内容:', res.content);
					
					if(res.content==''){
						uni.showToast({
							icon: 'error',
							title: '请输入内容'
						})
						return;
					}
					
					uni.showLoading({
						title: '数据加载中',
						mask:true
					});  
					http.request({
					 	url: "/x/partner/change/shop/status",
					 	method: "POST",
					 	data: {
							id:id.value,
							userId:userId.value,
							status:2,
							shopId:shopId.value,
							message:res.content
						}
					}).then((responseData) => { 
						uni.hideLoading();
						console.log(responseData)
						if(responseData.code==1){
							uni.showToast({
								icon: 'error',
								title: '成功'
							}) 
							initData();  
						}else if(responseData.code==0){
							uni.showToast({
								icon: 'error',
								title: responseData.message
							})
						}else if(responseData.code==-1){
							uni.navigateTo({
								url: "/pages/login/login"
							});
						}
					}).catch((err) => {
						uni.hideLoading();
					 	uni.showToast({
					 		icon: 'error',
					 		title: '请求失败'
					 	})
					}) 
		        } else if (res.cancel) {
		            console.log('用户点击取消');
		        }
		    }
		});
	}
	 
	function edit(status,message){
		var msg="确定通过？"; 
		uni.showModal({
		    title: '提示',
		    content: msg,
		    success: (res) => {
		        if (res.confirm) {
		            // 用户点击了确定按钮 
					uni.showLoading({
						title: '数据加载中',
						mask:true
					});  
					http.request({
					 	url: "/x/partner/change/shop/status",
					 	method: "POST",
					 	data: {
							id:id.value,
							userId:userId.value,
							status:status,
							shopId:shopId.value,
							message:message
						}
					}).then((responseData) => { 
						uni.hideLoading();
						console.log(responseData)
						if(responseData.code==1){
							uni.showToast({
								icon: 'error',
								title: '成功'
							}) 
							initData();  
						}else if(responseData.code==0){
							uni.showToast({
								icon: 'error',
								title: responseData.message
							})
						}else if(responseData.code==-1){
							uni.navigateTo({
								url: "/pages/login/login"
							});
						}
					}).catch((err) => {
						uni.hideLoading();
					 	uni.showToast({
					 		icon: 'error',
					 		title: '请求失败'
					 	})
					}) 
		        } else if (res.cancel) {
		            // 用户点击了取消按钮
		            console.log('用户取消了授权');
		        }
		    }
		});
	}
	var data=ref({});
	function initData(){
		http.request({
			url: "/x/partner/shop/get",
			method: "POST",
			data: {
				shopId: shopId.value
			}
		}).then((responseData) => { 
			if(responseData.code==1){
				responseData.data.idImage=JSON.parse(responseData.data.idImage);
				responseData.data.files=JSON.parse(responseData.data.files);
				data.value=responseData.data;
				//刷新上个页面数据
				const pages = getCurrentPages();
				const beforePage = pages[pages.length - 2];
				console.log(beforePage)
				if(beforePage){
					beforePage.$vm.$.exposed.pageIn(data.value) 
					//uni.navigateBack(); 
				}
			}  
		}).catch((err) => {
			uni.showToast({
				icon: 'error',
				title: '请求失败'
			})
		})
	}
	function previewImage(img) {
			console.log("1111111",img)
			wx.previewImage({
			  current: img, // 当前显示的图片链接
			  urls: [
				img
			  ],
			  success: function(res) {
				// 预览成功的回调函数
			  },
			  fail: function(err) {
				// 预览失败的回调函数
			  }
			});
	}
</script>

<style>
	Page{
		font-size: 28rpx;
	}
	.item{
		width: 80%;float: left;margin-left: 10%;margin-top: 20rpx;
	}
	.lb{
		color: #666666;
	}
	.clk{
		color: blue;margin-left: 15rpx;
	}
	.btn1{
		width: 20%;height: 60rpx;line-height: 60rpx;text-align: center;background: #CCCCCC;color: white;margin-left: 20%;float: left;
	}
	.btn2{
		width: 20%;height: 60rpx;line-height: 60rpx;text-align: center;background: #CCCCCC;color: white;float: left;margin-left: 20%;
	}
</style>